package com.blockmeta.bbs.immodule.dao;

import android.text.TextUtils;

public final class ChatMessageBuilder {
    private int unCheckedCount;
    private String uuid;
    private int status;
    private String fileGroupName;
    private String filePath;
    private int contentType;// 消息类型
    private int chatMessageId;
    //当前用户
    private long whoId;
    private Boolean checked;
    private Long id;
    //其他用户
    private long fromId;
    private int toId;
    private String content;
    private int date;//时间采用int 本地采用int值
    private int type;
    private int msgType;
    private int stick;
    private int chatGroupId;

    private int discussionGroupId;
    // 是否需要转发，如果传入的是clinet则需要转发，如果是服务端则说明本就是转发消息不需要转发
    private boolean transfer;
    //删除Attachment表，然后新增file_name，file_type
    private String fileName;
    //文件的类型
    private int fileType;
    private String fileParam;
    private String userName;
    private String userAvator;

    private ChatMessageBuilder() {
    }

    public static ChatMessage buildNotifyMsg(long id, String content, String uuid, long fromId, int toId, int type) {
        ChatMessage chatMessage = new ChatMessageBuilder()
                .setId(id)
                .setContent(content)
                .setType(ChatMessage.TYPE_RECEIVE)
                .setMsgType(type)
                .setToId(type == ChatMessage.MSG_TYPE_UU ? toId : 0)
                .setChatGroupId(type == ChatMessage.MSG_TYPE_UCG ? toId : 0)
                .setFromId(fromId)
                .setWhoId(fromId)
                .setContentType(ChatMessage.CONTENT_TYPE_NOTIFY)
                .setStatus(ChatMessage.STATUS_SEND)
                .setDate((int) (System.currentTimeMillis() / 1000L))
                .setChecked(true)
                .setUuid(uuid).build();
        return chatMessage;
    }

    public static ChatMessageBuilder aChatMessage() {
        return new ChatMessageBuilder();
    }

    public ChatMessageBuilder setUnCheckedCount(int unCheckedCount) {
        this.unCheckedCount = unCheckedCount;
        return this;
    }

    public ChatMessageBuilder setUuid(String uuid) {
        this.uuid = uuid;
        return this;
    }

    public ChatMessageBuilder setStatus(int status) {
        this.status = status;
        return this;
    }

    public ChatMessageBuilder setFileGroupName(String fileGroupName) {
        this.fileGroupName = fileGroupName;
        return this;
    }

    public ChatMessageBuilder setFilePath(String filePath) {
        this.filePath = filePath;
        return this;
    }

    public ChatMessageBuilder setContentType(int contentType) {
        this.contentType = contentType;
        return this;
    }

    public ChatMessageBuilder setChatMessageId(int chatMessageId) {
        this.chatMessageId = chatMessageId;
        return this;
    }

    public ChatMessageBuilder setWhoId(long whoId) {
        this.whoId = whoId;
        return this;
    }

    public ChatMessageBuilder setChecked(Boolean checked) {
        this.checked = checked;
        return this;
    }

    public ChatMessageBuilder setId(Long id) {
        this.id = id;
        return this;
    }

    public ChatMessageBuilder setFromId(long fromId) {
        this.fromId = fromId;
        return this;
    }

    public ChatMessageBuilder setToId(int toId) {
        this.toId = toId;
        return this;
    }

    public ChatMessageBuilder setContent(String content) {
        this.content = content;
        return this;
    }

    public ChatMessageBuilder setDate(int date) {
        this.date = date;
        return this;
    }

    public ChatMessageBuilder setType(int type) {
        this.type = type;
        return this;
    }

    public ChatMessageBuilder setMsgType(int msgType) {
        this.msgType = msgType;
        return this;
    }

    public ChatMessageBuilder setStick(int stick) {
        this.stick = stick;
        return this;
    }

    public ChatMessageBuilder setChatGroupId(int chatGroupId) {
        this.chatGroupId = chatGroupId;
        return this;
    }

    public ChatMessageBuilder setDiscussionGroupId(int discussionGroupId) {
        this.discussionGroupId = discussionGroupId;
        return this;
    }

    public ChatMessageBuilder setTransfer(boolean transfer) {
        this.transfer = transfer;
        return this;
    }

    public ChatMessageBuilder setFileName(String fileName) {
        this.fileName = fileName;
        return this;
    }

    public ChatMessageBuilder setFileType(int fileType) {
        this.fileType = fileType;
        return this;
    }

    public ChatMessageBuilder setFileParam(String fileParam) {
        this.fileParam = fileParam;
        return this;
    }

    public ChatMessageBuilder setUserName(String userName) {
        this.userName = userName;
        return this;
    }

    public ChatMessageBuilder setUserAvator(String userAvator) {
        this.userAvator = userAvator;
        return this;
    }

    public ChatMessage build() {

        if (TextUtils.isEmpty(uuid)) {
            throw new IllegalArgumentException("uuid is empty");
        }
        if (fromId == 0) {
            throw new IllegalArgumentException("fromId is 0");
        }
        if (toId == 0 && chatGroupId == 0) {
            throw new IllegalArgumentException("toid and groupid is 0");
        }
        if (date == 0) {
            throw new IllegalArgumentException("date is 0");
        }
        ChatMessage chatMessage = new ChatMessage();
        chatMessage.setUnCheckedCount(unCheckedCount);
        chatMessage.setUuid(uuid);
        chatMessage.setStatus(status);
        chatMessage.setFileGroupName(fileGroupName);
        chatMessage.setFilePath(filePath);
        chatMessage.setContentType(contentType);
        chatMessage.setChatMessageId(chatMessageId);
        chatMessage.setWhoId(whoId);
        chatMessage.setChecked(checked);
        chatMessage.setId(id);
        chatMessage.setFromId(fromId);
        chatMessage.setToId(toId);
        chatMessage.setContent(content);
        chatMessage.setDate(date);
        chatMessage.setType(type);
        chatMessage.setMsgType(msgType);
        chatMessage.setChatGroupId(chatGroupId);
        chatMessage.setDiscussionGroupId(discussionGroupId);
        chatMessage.setTransfer(transfer);
        chatMessage.setFileName(fileName);
        chatMessage.setFileType(fileType);
        chatMessage.setFileParam(fileParam);
        chatMessage.setUserName(userName);
        chatMessage.setUserAvator(userAvator);
        return chatMessage;
    }
}
